<%-- 
    Document   : top_liked
    Created on : Apr 25, 2012, 8:29:19 AM
    Author     : Dell
--%>
<%@ page language="java" import="java.sql.*" %>
<%@ page import="java.io.*,java.sql.*,java.util.*,java.text.*,java.text.SimpleDateFormat" %>
<%@ page import="java.util.List"%>  
<%@ page import="java.util.Iterator"%>  
<%@ page import="org.apache.commons.fileupload.*"%>  
<%@ page import="org.apache.commons.fileupload.disk.*"%>  
<%@ page import="org.apache.commons.fileupload.servlet.*"%> 
        <%
            String driver = "org.gjt.mm.mysql.Driver";
            Integer nowid;
            Class.forName(driver).newInstance();
            Connection con=null;
            ResultSet rst=null;
            ResultSet rsx=null;
            Statement stmt=null;
            
            try{
                 String url="jdbc:mysql://localhost:3306/progin_171_13509008?user=root";
                //String url ="jdbc:mysql://localhost:3306/user?user=root"; 
                con = DriverManager.getConnection(url);
                 stmt=con.createStatement();
                }
            catch(Exception e){
                    System.out.println(e.getMessage());
            }
            
            String query_1 = "Select user_name, content.id_content as id_konten, content.title, content.content_type, content.content_filled, content.posting_time from ";
	    String query_2 = "(Select c.id_content as e from ((Select b.id_content from (select id_content,count(*) as result from like_content where status = 1 group by id_content order by result desc) as b) ";
	    String query_3 = "union distinct ";
	    String query_4 = "(select not_like_result.id_content as not_like_result_id_content from (select id_content from like_content where status = 0 or status = 2 )as not_like_result)) as c) as most_like_order_id_content, content ";
            String query_5 = "where most_like_order_id_content.e = id_content limit 3";
            rst = stmt.executeQuery(query_1+query_2+query_3+query_4+query_5);
            
          
            
            while(rst.next())
            {
                if(rst.getString("content_type").equals("link"))
                {
                    out.println("<h1>"+rst.getString("title")+"</h1>");
                    out.println("<h2>"+rst.getString("content_filled")+"</h2>");
                    out.println("<h3>"+rst.getString("content_description")+"</h3>");
                    out.println("<h3>Posted by : <a href='detail.jsp'/>"+rst.getString("user_name")+"</a></h3>");
                }
                else if(rst.getString("content_type").equals("image"))
                {
                    out.println("<h1>"+rst.getString("title")+"</h1>");
                    out.println("<img src='"+rst.getString("content_filled")+"' height=500px width=this.width; ></img>");
                    out.println("<h3> Posted by : <a href='detail.jsp'/>"+rst.getString("user_name")+"</a></h3>");
                    
                }
                else if(rst.getString("content_type").equals("video"))
                {
                    out.println("<h1>"+rst.getString("title")+"</h1>");
                    out.println(rst.getString("content_filled"));
                    out.println("<h3>Posted by : <a href='detail.jsp'/>"+rst.getString("user_name")+"</a></h3>");
                    
                }                   
            
                out.println("<br><br>");
                out.println("<div id=infolikes>");
                out.println("<script type='text/javascript' src='script/home.js'></script>");
                out.println("<input id='like_"+rst.getInt("id_konten")+"' class='like_button' type='image' src='images/like_button.jpg' onclick='like(\""+session.getAttribute("user_name")+"\","+rst.getInt("id_konten")+")' style='float:left;'/>");
                out.println("<input class='total_like_class' type='text' disabled='disabled' id='total_like_"+rst.getInt("id_konten")+"'  />");
                out.println("<input id='dislike_'"+rst.getInt("id_konten")+" class='like_button' type='image' src='images/dislike_button.jpg' onclick='dislike(\""+session.getAttribute("user_name")+"\","+rst.getInt("id_konten")+")'/>");
                out.println("<input class='total_dislike_class' type='text' disabled='disabled' id='total_dislike_"+rst.getInt("id_konten")+"'/>");
                out.println(" </div>");
                out.println("<script type='text/javascript'>"); //hitung nilai like dan dislike dulu!
                out.println("likeUpdater("+rst.getInt("id_konten")+"); dislikeUpdater("+rst.getInt("id_konten")+");");
                out.println(" </script>");
                nowid = rst.getInt("id_konten");
              
              

            }
          
        %>
